package m.jclecai.com.utils;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import m.jclecai.com.MyApplication;


public class CalculateBetNums {

	/*

	 使用说明 ：
	 1）非混投
	 投注格式：codes ： SPF|170329001=3,170329002=1,170329003=0|2*1
	 计算奖金格式： => codes = 170329001>SPF=3(3.2),170329002>SPF=1(3.2),170329003>SPF=0(3.2)
	          => type = 2*1
	 2）混投
	 投注格式：codes ： HH|170329001>SPF=3/1+RQSPF=1,170329002>SPF=0|2*1
	 计算奖金格式： => codes = 170329001>SPF=3/1(3.2~2.95)+RQSPF=1(3.2),170329002>SPF=0(3.2)
	          => type = 2*1
	3) @170127003 表示 胆码

	 */


    private static HashMap<String, String[]> items = new HashMap<String, String[]>();
    public static HashMap<String, String> types = new HashMap<>();

    static {
        items.putAll(initPermAndCombin());
        types.put("1*1", "1");
        types.put("2*1", "2");
        types.put("2*3", "1 2");
        types.put("3*1", "3");
        types.put("3*3", "2");
        types.put("3*4", "2 3");
        types.put("3*7", "1 2 3");
        types.put("4*1", "4");
        types.put("4*2", "2");
        types.put("4*4", "3");
        types.put("4*5", "3 4");
        types.put("4*6", "2");
        types.put("4*11", "2 3 4");
        types.put("4*15", "1 2 3 4");
        types.put("5*1", "5");
        types.put("5*2", "2");
        types.put("5*5", "4");
        types.put("5*6", "4 5");
        types.put("5*10", "2");
        types.put("5*16", "3 4 5");
        types.put("5*20", "2 3");
        types.put("5*26", "2 3 4 5");
        types.put("5*31", "1 2 3 4 5");
        types.put("6*1", "6");
        types.put("6*2", "2");
        types.put("6*6", "5");
        types.put("6*7", "5 6");
        types.put("6*15", "2");
        types.put("6*20", "3");
        types.put("6*22", "4 5 6");
        types.put("6*35", "2 3");
        types.put("6*42", "3 4 5 6");
        types.put("6*50", "2 3 4");
        types.put("6*57", "2 3 4 5 6");
        types.put("6*63", "1 2 3 4 5 6");
        types.put("7*1", "7");
        types.put("7*7", "6");
        types.put("7*8", "6 7");
        types.put("7*21", "5");
        types.put("7*35", "4");
        types.put("7*120", "2 3 4 5 6 7");
        types.put("8*1", "8");
        types.put("8*8", "7");
        types.put("8*9", "7 8");
        types.put("8*28", "6");
        types.put("8*56", "5");
        types.put("8*70", "4");
        types.put("8*247", "2 3 4 5 6 7 8");
        types.put("9*1", "9");
        types.put("10*1", "10");
        types.put("11*1", "11");
        types.put("12*1", "12");
        types.put("13*1", "13");
        types.put("14*1", "14");
        types.put("15*1", "15");

    }


    /**
     * 初始化排列组合的内容；
     */
    public static HashMap<String,String[]> initPermAndCombin() {

        Context context= MyApplication.getAppContext();
        InputStream open = null;
        Reader reader = null;
        BufferedReader bufferedReader = null;
        HashMap<String,String[]> mapInt=new HashMap<>();

        try {
            //读取文件
            open = context.getAssets().open("permAndCombin.txt");
            //这里我们将读取数据；
            reader = new InputStreamReader(open);
            bufferedReader = new BufferedReader(reader);
            String str = "";
            while (true) {
                str = bufferedReader.readLine();
                if (str != null) {
                    //这里我们要做的一个操作就是
                    String[] strings = str.split("=");
                    String[] allOptions = strings[1].split(",");
                    mapInt.put(strings[0],allOptions);
                } else {
                    break;
                }
            }
            //这里对其进行一个初始化；
            bufferedReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return mapInt;
    }


    public int getVoteNums(String vote, String buyType) {

        String wagerType = "Combin";
        int zs = 0;

        List<Integer> sa = new ArrayList<Integer>();
        List<Integer> sb = new ArrayList<Integer>();

        String[] betMatchNum = vote.split(",");

        if ("Combin".equals(buyType)) {
            buyType = "1*1";
        }

        for (int i = 0; i < betMatchNum.length; i++) {
            String data = betMatchNum[i];
            System.out.println("data =" + data);
            if (data.indexOf("@") > -1) {//// 有胆码的
                String[] res = data.split(">")[1].split("\\+");
                int len = 0;
                for (int k = 0; k < res.length; k++) {
                    len += res[k].split("/").length;
                }
                sb.add(len);
            } else {
                String[] res = data.split(">")[1].split("\\+");
                int lens = 0;
                for (int k = 0; k < res.length; k++) {
                    lens += res[k].split("/").length;
                }
                sa.add(lens);
            }

        }


        int[] sas = new int[sa.size()];
        for (int i = 0; i < sa.size(); i++) {
            sas[i] = (int) sa.get(i);
        }

        int[] sbs = new int[sb.size()];
        for (int i = 0; i < sb.size(); i++) {
            sbs[i] = (int) sb.get(i);
        }
       /* int minabs = sa.size();*/

        int minabs = sb.size();
        int maxabs = sb.size();

        String[] buyType_arr = buyType.split(",");

        for (int j = 0; j < buyType_arr.length; j++) {
            zs += myCalc(buyType_arr[j], wagerType, sas, sbs, minabs, maxabs);

        }
        return zs;
    }

    public static String GetVotetype(String a) {
        return types.get(a);
    }


    public static List debuildVote(List<String> votes) {


        List<String> result = new ArrayList<String>();
        for (int j = 0; j < votes.size(); j++) {
            //170127002>SPF=3/1+RQSPF=3/0,@170127003>SPF=1+RQSPF=0,170127005>SPF=1
            String votestr = votes.get(j).replace("@", "");
            // System.out.println("votes:"+ votestr);
            String[] vote_arr = votestr.split(",");
            List<String> res = new ArrayList<String>();
            int c = vote_arr.length;
            for (int k = 0; k < c; k++) {
                //System.out.println("vote:"+vote_arr[k]);
                String[] q_arr = vote_arr[k].split("\\>");
                String expect = q_arr[0];
                String codes = q_arr[1];
                // System.out.println("expect:"+expect);
                //  System.out.println("codes:"+codes);
                String[] c_arr = codes.split("\\+");
                for (int l = 0; l < c_arr.length; l++) {
                    String str = expect + ">" + c_arr[l];
                    res.add(str);
                }
            }
            int counts = res.size();
//            String k = items.get(counts + "_" + c);

            String[] y = items.get(counts + "_" + c);
            //console.log(y);
            List<String> e_arr = new ArrayList<String>();

            for (int m = 0; m < y.length; m++) {
                String[] z = y[m].split("/");
                int p = z.length;
                // System.out.println("p:"+p);
                List<String> codes = new ArrayList<String>();

                for (int n = 0; n < p; n++) {
                    int parseInt = Integer.parseInt(z[n]);
                    String o = res.get(parseInt - 1);
                    String[] q_arr = o.split("\\>");
                    String expect = q_arr[0];
                    e_arr.add(expect);
                    codes.add(o);
                }

                Collections.sort(codes);
                String code = "";
                for (int i = 0; i < codes.size(); i++) {
                    code += codes.get(i) + ",";
                }
                code = code.substring(0, code.length() - 1);
                result.add(code);
                // System.out.println("code:"+code);
                for (int t = 0; t < e_arr.size(); t++) {
                    int n = (code.split(e_arr.get(t))).length - 1;
                    if (n > 1) result.remove(code);
                }
            }

        }

        Set set = new HashSet();
        List<String> results = new ArrayList<String>();
        for (String cd : result) {
            if (set.add(cd)) {
                // System.out.println("cd:"+cd);
                results.add(cd);
            }
        }
        return results;
    }


    public static List<String> rebuildVote(String votes, String types) {
        String[] vote_arr = votes.split(",");
        int counts = vote_arr.length;
        String[] types_arr = types.split(",");
        List<String> res = new ArrayList<String>();
        for (int q = 0; q < types_arr.length; q++) {
            String type = types_arr[q];
            //System.out.println(type);
            String type_str = GetVotetype(type);
            // System.out.println("type_str="+type_str);
            String[] type_arr = type_str.split(" ");

            for (int i = 0; i < type_arr.length; i++) {
                String c = type_arr[i];
                // String k = items.get(counts + "_" + c);
                // System.out.println("k="+k);
                String[] y = items.get(counts+"_"+c);

                for (int m = 0; m < y.length; m++) {
                    String[] z = y[m].split("/");
                    int p = z.length;
                    List<String> codes = new ArrayList<String>();
                    for (int n = 0; n < p; n++) {
                        int parseInt1 = Integer.parseInt(z[n]);
                        String o = vote_arr[parseInt1 - 1];
                        codes.add(o);
                    }

                    String code = "";
                    for (int h = 0; h < codes.size(); h++) {
                        code += codes.get(h) + ",";
                    }
                    code = code.substring(0, code.length() - 1);
                    //System.out.println("code=>"+code);
                    res.add(code);
                }
            }
        }
        if (votes.contains("@")) {

            List<String> arr = new ArrayList<String>();

            for (int k =0; k < res.size(); k++) {

                 if (!res.get(k).contains("@")) {
                     res.remove(k);
                 }

            }

            for (int k = 0; k < res.size(); k++) {
//                if (!res.get(k).contains("@")) {
                    arr.add(res.get(k));
//                }
            }
            res = arr;
        }

        return debuildVote(res);
        //return res;
    }

    public static double ListDoubleArrayMax(List<Double> dataList) {
        double max = Double.MIN_VALUE;

        for (double d : dataList) {
            if (d > max) {
                max = d;
            }
        }

        return max;
    }

    public static double ListDoubleArrayMin(List<Double> dataList) {
        double min = Double.MAX_VALUE;

        for (double d : dataList) {
            if (d < min) {
                min = d;
            }
        }

        return min;
    }

    public static String getBonus(List<String> rebuildVote,int type,int flag) {
        DecimalFormat df = new DecimalFormat("#0.00");
        double  bonus = 0.00000D;
        List<Double> bonus_min = new ArrayList<Double>();

        HashMap<String, String> h_odds = new HashMap<String, String>();
        for (int q = 0; q < rebuildVote.size(); q++) {
            String str = rebuildVote.get(q);
            String[] vote_arr =str.split(",");
            double b=1,a=1;
            List<String> issue = new ArrayList<String>();

            for (int i = 0; i < vote_arr.length; i++) {
                //让球只适合“让球胜平负”玩法，“+”为客让主，“-”为主让客。

	        	  /*if (i==0){
	        	  //170329007>RQSPF=1/0(3.95~1.36),170329008>SPF=0(2.53)
	        	  String v_arr[] = vote_arr[i].split("=");
	        	  issue.add(v_arr[0]);
	        	  }else{*/
                issue.add(vote_arr[i].substring(0, 9));
                //}


                String regex="\\((.+?)\\)";
                // String regex="\\[(.*?)\\]";
                List<Double> sp = new ArrayList<Double>();
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(vote_arr[i]);
                String sp_str = "";
                while(matcher.find()){
                    sp_str = matcher.group(1);
                }

                String[] sp_arr = sp_str.split("~");
                for(int k=0;k<sp_arr.length;k++){
                    //System.out.println("sp_str_=>"+  Double.parseDouble(sp_arr[k]));
                    sp.add(  Double.parseDouble(sp_arr[k]) );
                }

                double  sp_max = ListDoubleArrayMax(sp);
                double  sp_min = ListDoubleArrayMin(sp);
                //System.out.println("sp_max=>"+sp_max);
                //System.out.println("sp_min=>"+sp_min);
                b *= sp_max;
                a *= sp_min;

            }
            Collections.sort(issue);
            String issues="";
            for(int i=0;i<issue.size();i++){
                issues+=issue.get(i);
                System.out.println("issue=>"+issue.get(i));
            }
            String s_odds =  h_odds.get(issues);
            if   (s_odds == null ||  s_odds.length() <= 0 ){
                h_odds.put(issues,b+"");
            }else{
                if   (	b>parseFloat(s_odds) ) {
                    h_odds.put(issues,b+"");
                }
            }
            double sp_val = a*2*flag;
            //System.out.println("a=>"+a);
            bonus_min.add(sp_val);
        }

        List<Double> odds_max = new ArrayList<Double>();
        for (String key : h_odds.keySet()) {
            bonus += Double.parseDouble(h_odds.get(key));
            System.out.println("bouns=>"+ 2*Double.parseDouble(h_odds.get(key)));
            odds_max.add(  Double.parseDouble(h_odds.get(key)) );
        }
        //bonus -= ListDoubleArrayMin(odds_max); //减去一个最小值，不清楚原理  by QQ:2196093807

        if (type==1) {
            double sp_max =bonus * 2 * flag;
            return df.format(sp_max);
        }else{
            double sp_min = ListDoubleArrayMin(bonus_min);
            return df.format(sp_min);
        }
    }

    private int myCalc(String passType, String wagerType, int[] sa, int[] sb, int minabs, int maxabs) {
        if (sb.length == 0) {
            return calc(passType, wagerType, sa, sb);
        } else {
            int wcount = 0;
            for (int k = minabs; k <= maxabs; k++) {
                List<int[]> bm = combinArray(sb, k);
                for (int j = 0; j < bm.size(); j++) {
                    //System.out.println("返回的值:"+bm.get(j));
                    //wcount += calc(passType, wagerType, sa, bm.get(j));
                    int[] ttmp = bm.get(j);
                    wcount += calc(passType, wagerType, sa,ttmp);
                }
            }
            return wcount;
        }
    }

    private int calc(String passType, String wagerType, int[] sa, int[] sb) {
        int WagerCount = 0;
        String[] t_list = passType.split("\\*");
        int pc = Integer.parseInt(t_list[0]);

        if ("Combin".equals(wagerType)) {
            int AbsCount = sb.length;
            int len = pc - AbsCount;
            if (len == 0 && AbsCount > 0) {
                int[] pm = new int[pc];
                for (int P = 0; P < sb.length; P++) {
                    int AbsVoteC = sb[P];
                    for (int k = 0; k < pc; k++) {
                        if (pm[k] == 0) {
                            pm[k] = AbsVoteC;
                            break;
                        }
                    }
                }

                String pstr = "";
                for (int i = 0; i < pc; i++) {
                    pstr += pm[i] + ",";
                }
                pstr = pstr.substring(0, pstr.length() - 1);
                WagerCount += calcuteWC(passType, pstr);
            } else {
                int[] arr = new int[sa.length];
                for (int i = 0; i < sa.length; i++) {
                    arr[i] = i;
                }

                List<int[]> w = combinArray(arr, len);
                //System.out.println("w:"+w.size());

            /*    for (int i = 0; i < w.size(); i++) {
                    int[] splitArr = w.get(i);
                    int[] pm = new int[pc];
                    for (int k = 0; k < pc; k++) {
                        if (k > splitArr.length - 1) break;
                        int d = splitArr[k];
                        pm[k] = parseFloat(sa[d] + "");
                    }

                    if (AbsCount > 0) {*/

                for (int i = 0; i < w.size(); i++) {
                    int[] splitArr = w.get(i);
                    System.out.println("ww:"+ w.get(i));


                    int[] ttmp = w.get(i);
                    for (int y = 0; y < ttmp.length; y++) {
                        System.out.println("ww返回的值"+ ttmp[y]);
                    }



                    int[] pm = new int[pc];
                    for (int k = 0; k < ttmp.length; k++) {
                        System.out.println("KK:"+k);
                        int d = splitArr[k];
                        pm[k] = parseFloat(sa[d]+"");
                    }

                    if (AbsCount > 0) {
                        for (int p = 0; p < sb.length; p++) {
                            int AbsVoteC = sb[p];
                            for (int k = 0; k < pc; k++) {

								/*
                                try {
							        Pattern rp = Pattern.compile("^\\d+");
							        Matcher m = rp.matcher(String.valueOf(pm[k]));
							        if (!m.find()) {
							        	pm[k] = AbsVoteC;
										break;
							        }
							    } catch (NumberFormatException e) {
							        e.printStackTrace();
							    }
							    */


                                if (pm[k] == 0 || "null".equals(String.valueOf(pm[k]))) {
                                    pm[k] = AbsVoteC;
                                    break;
                                }
                            }
                        }
                    }

                    String pstr = "";
                    for (int n = 0; n < pc; n++) {
                        pstr += pm[n] + ",";
                    }
                    pstr = pstr.substring(0, pstr.length() - 1);
                    //System.out.println("pstr:"+pstr);
                    WagerCount += calcuteWC(passType, pstr);
                }
            }
        } else if ("Subsection".equals(wagerType)) {
            // //to do
            WagerCount += 0;
        }

        return WagerCount;
    }


    //从长度为n的数组中随机的选择m个整数


    private List<int[]> combinArray(int[] a, int m) {
        Arrays.sort(a);
        List<int[]> list = new ArrayList<int[]>();
        int n = a.length;
        if (n <= m) {
            list.add(a);// 添加下一种默认组合
        } else {
            boolean end = false; // 是否是最后一种组合的标记
            // 生成辅助数组。首先初始化，将数组前n个元素置1，表示第一个组合为前n个数。
            int[] tempNum = new int[n];
            for (int i = 0; i < n; i++) {
                if (i < m) {
                    tempNum[i] = 1;
                } else {
                    tempNum[i] = 0;
                }
            }
            list.add(createResult(a, tempNum, m));// 打印第一种默认组合
            int k = 0;//标记位
            while (!end) {
                boolean findFirst = false;
                boolean swap = false;
                // 然后从左到右扫描数组元素值的"10"组合，找到第一个"10"组合后将其变为"01"
                for (int i = 0; i < n; i++) {
                    int l = 0;
                    if (!findFirst && tempNum[i] == 1) {
                        k = i;
                        findFirst = true;
                    }
                    if (tempNum[i] == 1 && tempNum[i + 1] == 0) {
                        tempNum[i] = 0;
                        tempNum[i + 1] = 1;
                        swap = true;
                        for (l = 0; l < i - k; l++) { // 同时将其左边的所有"1"全部移动到数组的最左端。
                            tempNum[l] = tempNum[k + l];
                        }
                        for (l = i - k; l < i; l++) {
                            tempNum[l] = 0;
                        }
                        if (k == i && i + 1 == n - m) {//假如第一个"1"刚刚移动到第n-m+1个位置,则终止整个寻找
                            end = true;
                        }
                    }
                    if (swap) {
                        break;
                    }
                }

                list.add(createResult(a, tempNum, m));// 添加下一种默认组合
            }

        }
        return list;
    }


    // 根据辅助数组和原始数组生成结果数组
    public int[] createResult(int[] a, int[] temp, int m) {
        int[] result = new int[m];
        int j = 0;
        for (int i = 0; i < a.length; i++) {
            if (temp[i] == 1) {
                result[j] = a[i];
                // System.out.println("result[" + j + "]:" + result[j]);
                j++;
            }
        }
        return result;
    }


    private int[][] subsectionArray(int[] arr, int len) {
        //to do
        int[][] ar = new int[][]{};
        return ar;
    }


    public int calcuteWC(String passtype, String str) {
        String[] arr = str.split(",");
        int re = 0,
                a = parseFloat(arr[0]),
                b = (arr.length > 1) ? parseFloat(arr[1]) : 0,
                c = (arr.length > 2) ? parseFloat(arr[2]) : 0,
                d = (arr.length > 3) ? parseFloat(arr[3]) : 0,
                e = (arr.length > 4) ? parseFloat(arr[4]) : 0,
                f = (arr.length > 5) ? parseFloat(arr[5]) : 0,
                g = (arr.length > 6) ? parseFloat(arr[6]) : 0,
                h = (arr.length > 7) ? parseFloat(arr[7]) : 0,
                i = (arr.length > 8) ? parseFloat(arr[8]) : 0,
                j = (arr.length > 9) ? parseFloat(arr[9]) : 0,
                k = (arr.length > 10) ? parseFloat(arr[10]) : 0,
                l = (arr.length > 11) ? parseFloat(arr[11]) : 0,
                m = (arr.length > 12) ? parseFloat(arr[12]) : 0,
                n = (arr.length > 13) ? parseFloat(arr[13]) : 0,
                o = (arr.length > 14) ? parseFloat(arr[14]) : 0;

        if (passtype.equals("1*1")) {
            re = a;

        } else if (passtype.equals("2*1")) {
            re = a * b;

        } else if (passtype.equals("2*3")) {
            re = (a + 1) * (b + 1) - 1;

        } else if (passtype.equals("3*1")) {
            re = a * b * c;

        } else if (passtype.equals("3*3")) {
            re = a * b + a * c + b * c;

        } else if (passtype.equals("3*4")) {
            re = a * b * c + a * b + a * c + b * c;

        } else if (passtype.equals("3*7")) {
            re = (a + 1) * (b + 1) * (c + 1) - 1;

        } else if (passtype.equals("4*1")) {
            re = a * b * c * d;

        } else if (passtype.equals("4*4")) {
            re = a * b * c + a * b * d + a * c * d + b * c * d;

        } else if (passtype.equals("4*5")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - (a * (b + c + d + 1) + b * (c + d + 1) + (c + 1) * (d + 1));

        } else if (passtype.equals("4*6")) {
            re = a * b + a * c + a * d + b * c + b * d + c * d;

        } else if (passtype.equals("4*11")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - (a + b + c + d + 1);

        } else if (passtype.equals("4*15")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - 1;

        } else if (passtype.equals("5*1")) {
            re = a * b * c * d * e;

        } else if (passtype.equals("5*5")) {
            re = a * b * c * d + a * b * c * e + a * b * d * e + a * c * d * e + b * c * d * e;

        } else if (passtype.equals("5*6")) {
            re = a * b * c * d * e + a * b * c * d + a * b * c * e + a * b * d * e + a * c * d * e + b * c * d * e;

        } else if (passtype.equals("5*10")) {
            re = a * b + a * c + a * d + a * e + b * c + b * d + b * e + c * d + c * e + d * e;

        } else if (passtype.equals("5*16")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - (a * (b + c + d + e + 1) + b * (c + d + e + 1) + c * (d + e + 1) + (d + 1) * (e + 1));

        } else if (passtype.equals("5*20")) {
            re = a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e + b * c * d + b * c * e + b * d * e + c * d * e + a * b + a * c + a * d + a * e + b * c + b * d + b * e + c * d + c * e + d * e;

        } else if (passtype.equals("5*26")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - (a + b + c + d + e + 1);

        } else if (passtype.equals("5*31")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - 1;

        } else if (passtype.equals("6*1")) {
            re = a * b * c * d * e * f;

        } else if (passtype.equals("6*6")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f;

        } else if (passtype.equals("6*7")) {
            re = a * b * c * d * e * f + a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f;

        } else if (passtype.equals("6*15")) {
            re = a * b + a * c + a * d + a * e + a * f + b * c + b * d + b * e + b * f + c * d + c * e + c * f + d * e + d * f + e * f;

        } else if (passtype.equals("6*20")) {
            re = a * b * c + a * b * d + a * b * e + a * b * f + a * c * d + a * c * e + a * c * f + a * d * e + a * d * f + a * e * f + b * c * d + b * c * e + b * c * f + b * d * e + b * d * f + b * e * f + c * d * e + c * d * f + c * e * f + d * e * f;

        } else if (passtype.equals("6*22")) {
            re = a * b * c * d * e * f + a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f + a * b * c * d + a * b * c * e + a * b * c * f + a * b * d * e + a * b * d * f + a * b * e * f + a * c * d * e + a * c * d * f + a * c * e * f + a * d * e * f + b * c * d * e + b * c * d * f + b * c * e * f + b * d * e * f + c * d * e * f;

        } else if (passtype.equals("6*35")) {
            re = a * b * c + a * b * d + a * b * e + a * b * f + a * c * d + a * c * e + a * c * f + a * d * e + a * d * f + a * e * f + b * c * d + b * c * e + b * c * f + b * d * e + b * d * f + b * e * f + c * d * e + c * d * f + c * e * f + d * e * f + a * b + a * c + a * d + a * e + a * f + b * c + b * d + b * e + b * f + c * d + c * e + c * f + d * e + d * f + e * f;

        } else if (passtype.equals("6*42")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a * (b + c + d + e + f + 1) + b * (c + d + e + f + 1) + c * (d + e + f + 1) + d * (e + f + 1) + (e + 1) * (f + 1));

        } else if (passtype.equals("6*50")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a + b + c + d + e + f + 1) - (a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f + a * b * c * d * e * f);

        } else if (passtype.equals("6*57")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a + b + c + d + e + f + 1);

        } else if (passtype.equals("6*63")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - 1;

        } else if (passtype.equals("7*1")) {
            re = a * b * c * d * e * f * g;

        } else if (passtype.equals("7*7")) {
            re = a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * f * g + a * b * c * e * f * g + a * b * d * e * f * g + a * c * d * e * f * g + b * c * d * e * f * g;

        } else if (passtype.equals("7*8")) {
            re = a * b * c * d * e * f * g + a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * f * g + a * b * c * e * f * g + a * b * d * e * f * g + a * c * d * e * f * g + b * c * d * e * f * g;

        } else if (passtype.equals("7*21")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * d * g + a * b * c * e * f + a * b * c * e * g + a * b * c * f * g + a * b * d * e * f + a * b * d * e * g + a * b * d * f * g + a * b * e * f * g + a * c * d * e * f + a * c * d * e * g + a * c * d * f * g + a * c * e * f * g + a * d * e * f * g + b * c * d * e * f + b * c * d * e * g + b * c * d * f * g + b * c * e * f * g + b * d * e * f * g + c * d * e * f * g;

        } else if (passtype.equals("7*35")) {
            re = a * b * c * d + a * b * c * e + a * b * c * f + a * b * c * g + a * b * d * e + a * b * d * f + a * b * d * g + a * b * e * f + a * b * e * g + a * b * f * g + a * c * d * e + a * c * d * f + a * c * d * g + a * c * e * f + a * c * e * g + a * c * f * g + a * d * e * f + a * d * e * g + a * d * f * g + a * e * f * g + b * c * d * e + b * c * d * f + b * c * d * g + b * c * e * f + b * c * e * g + b * c * f * g + b * d * e * f + b * d * e * g + b * d * f * g + b * e * f * g + c * d * e * f + c * d * e * g + c * d * f * g + c * e * f * g + d * e * f * g;

        } else if (passtype.equals("7*120")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) * (g + 1) - (a + b + c + d + e + f + g + 1);

        } else if (passtype.equals("8*1")) {
            re = a * b * c * d * e * f * g * h;

        } else if (passtype.equals("8*8")) {
            re = a * b * c * d * e * f * g + a * b * c * d * e * f * h + a * b * c * d * e * g * h + a * b * c * d * f * g * h + a * b * c * e * f * g * h + a * b * d * e * f * g * h + a * c * d * e * f * g * h + b * c * d * e * f * g * h;

        } else if (passtype.equals("8*9")) {
            re = a * b * c * d * e * f * g * h + a * b * c * d * e * f * g + a * b * c * d * e * f * h + a * b * c * d * e * g * h + a * b * c * d * f * g * h + a * b * c * e * f * g * h + a * b * d * e * f * g * h + a * c * d * e * f * g * h + b * c * d * e * f * g * h;

        } else if (passtype.equals("8*28")) {
            re = a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * e * h + a * b * c * d * f * g + a * b * c * d * f * h + a * b * c * d * g * h + a * b * c * e * f * g + a * b * c * e * f * h + a * b * c * e * g * h + a * b * c * f * g * h + a * b * d * e * f * g + a * b * d * e * f * h + a * b * d * e * g * h + a * b * d * f * g * h + a * b * e * f * g * h + a * c * d * e * f * g + a * c * d * e * f * h + a * c * d * e * g * h + a * c * d * f * g * h + a * c * e * f * g * h + a * d * e * f * g * h + b * c * d * e * f * g + b * c * d * e * f * h + b * c * d * e * g * h + b * c * d * f * g * h + b * c * e * f * g * h + b * d * e * f * g * h + c * d * e * f * g * h;

        } else if (passtype.equals("8*56")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * d * g + a * b * c * d * h + a * b * c * e * f + a * b * c * e * g + a * b * c * e * h + a * b * c * f * g + a * b * c * f * h + a * b * c * g * h + a * b * d * e * f + a * b * d * e * g + a * b * d * e * h + a * b * d * f * g + a * b * d * f * h + a * b * d * g * h + a * b * e * f * g + a * b * e * f * h + a * b * e * g * h + a * b * f * g * h + a * c * d * e * f + a * c * d * e * g + a * c * d * e * h + a * c * d * f * g + a * c * d * f * h + a * c * d * g * h + a * c * e * f * g + a * c * e * f * h + a * c * e * g * h + a * c * f * g * h + a * d * e * f * g + a * d * e * f * h + a * d * e * g * h + a * d * f * g * h + a * e * f * g * h + b * c * d * e * f + b * c * d * e * g + b * c * d * e * h + b * c * d * f * g + b * c * d * f * h + b * c * d * g * h + b * c * e * f * g + b * c * e * f * h + b * c * e * g * h + b * c * f * g * h + b * d * e * f * g + b * d * e * f * h + b * d * e * g * h + b * d * f * g * h + b * e * f * g * h + c * d * e * f * g + c * d * e * f * h + c * d * e * g * h + c * d * f * g * h + c * e * f * g * h + d * e * f * g * h;

        } else if (passtype.equals("8*70")) {
            re = a * b * c * d + a * b * c * e + a * b * c * f + a * b * c * g + a * b * c * h + a * b * d * e + a * b * d * f + a * b * d * g + a * b * d * h + a * b * e * f + a * b * e * g + a * b * e * h + a * b * f * g + a * b * f * h + a * b * g * h + a * c * d * e + a * c * d * f + a * c * d * g + a * c * d * h + a * c * e * f + a * c * e * g + a * c * e * h + a * c * f * g + a * c * f * h + a * c * g * h + a * d * e * f + a * d * e * g + a * d * e * h + a * d * f * g + a * d * f * h + a * d * g * h + a * e * f * g + a * e * f * h + a * e * g * h + a * f * g * h + b * c * d * e + b * c * d * f + b * c * d * g + b * c * d * h + b * c * e * f + b * c * e * g + b * c * e * h + b * c * f * g + b * c * f * h + b * c * g * h + b * d * e * f + b * d * e * g + b * d * e * h + b * d * f * g + b * d * f * h + b * d * g * h + b * e * f * g + b * e * f * h + b * e * g * h + b * f * g * h + c * d * e * f + c * d * e * g + c * d * e * h + c * d * f * g + c * d * f * h + c * d * g * h + c * e * f * g + c * e * f * h + c * e * g * h + c * f * g * h + d * e * f * g + d * e * f * h + d * e * g * h + d * f * g * h + e * f * g * h;

        } else if (passtype.equals("8*247")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) * (g + 1) * (h + 1) - (a + b + c + d + e + f + g + h + 1);

        } else if (passtype.equals("9*1")) {
            re = a * b * c * d * e * f * g * h * i;

        } else if (passtype.equals("10*1")) {
            re = a * b * c * d * e * f * g * h * i * j;

        } else if (passtype.equals("11*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k;

        } else if (passtype.equals("12*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l;

        } else if (passtype.equals("13*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m;

        } else if (passtype.equals("14*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m * n;

        } else if (passtype.equals("15*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m * n * o;
        }
        return re;
    }

    private static int parseFloat(String str) {
        int i = 0;
        try {
            Pattern p = Pattern.compile("^\\d+");
            Matcher m = p.matcher(str);
            if (m.find()) {
                i = Integer.valueOf(m.group());
            } else {
                i = 0;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return i;
    }


    public static void main(String[] a) {

        int[] arr = {0, 1}; // 整数数组
        int m = 2; // 待取出组合的个数

        CalculateBetNums calculateBetNums = new CalculateBetNums();
        List<int[]> list = calculateBetNums.combinArray(arr, m);
        //System.out.println("一共" + list.size() + "组!");

        for (int x = 0; x < list.size(); x++) {
            int[] ttmp = list.get(x);
            for (int y = 0; y < ttmp.length; y++) {
                //System.out.println("返回的值"+ ttmp[y]);
            }
            //System.out.println("---------------");
        }


        //String vote = "170329001>SPF=3/1(3.2~2.95)+RQSPF=1(3.2),170329002>SPF=0(3.2),170329003>SPF=0(3.2),170329004>SPF=0(3.2)";

        String vote= "170329001>SPF=3(3.2),"
                + "@170329002>SPF=3(3.2),"
                + "170329003>SPF=3(3.2),"
                + "170329004>SPF=3(3.2),"
                + "170329005>SPF=3(3.2),"
                + "170329006>SPF=3(3.2),"
                //+ "170329007>SPF=3(3.2)+RQSPF=3(3.2),"
                + "170329008>SPF=3(3.2)";

        //vote= "180427007>SPF=3(3.2),180427008>SPF=1(3.2),@180427009>SPF=3(3.2),@180427010>SPF=1(3.2)";
        //String buyType="2*1,3*1";
        String buyType="7*1";
        // String buyType = "2*1,3*1";
        int voteNums = calculateBetNums.getVoteNums(vote, buyType);
        System.out.println("注数：" + voteNums);

        List<String> rebuildVote = rebuildVote(vote, buyType);
        for (int m1 = 0; m1 < rebuildVote.size(); m1++) {
            //System.out.println("("+m1+") code = "+rebuildVote.get(m1));
        }
        String sp_max = getBonus(rebuildVote, 1, 1);
        String sp_min = getBonus(rebuildVote, 0, 1);
        System.out.println("最小奖金：" + sp_min);
        System.out.println("最大奖金：" + sp_max);
    }




}

